<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 20] The java.awt.event Package</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:13:41 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">
<script language='JavaScript'>
<!--
if (location.replace) {
 location.replace ('ch20_js.htm');
}
// -->
</script>

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_06.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 20</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch20_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JNUT2-CH-20">20. The java.awt.event Package</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
<a href='ch20_02.htm'>java.awt.event.ActionListener (JDK 1.1)</a><br>
<a href='ch20_03.htm'>java.awt.event.AdjustmentEvent (JDK 1.1)</a><br>
<a href='ch20_04.htm'>java.awt.event.AdjustmentListener (JDK 1.1)</a><br>
<a href='ch20_05.htm'>java.awt.event.ComponentAdapter (JDK 1.1)</a><br>
<a href='ch20_06.htm'>java.awt.event.ComponentEvent (JDK 1.1)</a><br>
<a href='ch20_07.htm'>java.awt.event.ComponentListener (JDK 1.1)</a><br>
<a href='ch20_08.htm'>java.awt.event.ContainerAdapter (JDK 1.1)</a><br>
<a href='ch20_09.htm'>java.awt.event.ContainerEvent (JDK 1.1)</a><br>
<a href='ch20_10.htm'>java.awt.event.ContainerListener (JDK 1.1)</a><br>
<a href='ch20_11.htm'>java.awt.event.FocusAdapter (JDK 1.1)</a><br>
<a href='ch20_12.htm'>java.awt.event.FocusEvent (JDK 1.1)</a><br>
<a href='ch20_13.htm'>java.awt.event.FocusListener (JDK 1.1)</a><br>
<a href='ch20_14.htm'>java.awt.event.InputEvent (JDK 1.1)</a><br>
<a href='ch20_15.htm'>java.awt.event.ItemEvent (JDK 1.1)</a><br>
<a href='ch20_16.htm'>java.awt.event.ItemListener (JDK 1.1)</a><br>
<a href='ch20_17.htm'>java.awt.event.KeyAdapter (JDK 1.1)</a><br>
<a href='ch20_18.htm'>java.awt.event.KeyEvent (JDK 1.1)</a><br>
<a href='ch20_19.htm'>java.awt.event.KeyListener (JDK 1.1)</a><br>
<a href='ch20_20.htm'>java.awt.event.MouseAdapter (JDK 1.1)</a><br>
<a href='ch20_21.htm'>java.awt.event.MouseEvent (JDK 1.1)</a><br>
<a href='ch20_22.htm'>java.awt.event.MouseListener (JDK 1.1)</a><br>
<a href='ch20_23.htm'>java.awt.event.MouseMotionAdapter (JDK 1.1)</a><br>
<a href='ch20_24.htm'>java.awt.event.MouseMotionListener (JDK 1.1)</a><br>
<a href='ch20_25.htm'>java.awt.event.PaintEvent (JDK 1.1)</a><br>
<a href='ch20_26.htm'>java.awt.event.TextEvent (JDK 1.1)</a><br>
<a href='ch20_27.htm'>java.awt.event.TextListener (JDK 1.1)</a><br>
<a href='ch20_28.htm'>java.awt.event.WindowAdapter (JDK 1.1)</a><br>
<a href='ch20_29.htm'>java.awt.event.WindowEvent (JDK 1.1)</a><br>
<a href='ch20_30.htm'>java.awt.event.WindowListener (JDK 1.1)</a><br>
<p>
<p>
</DIV>

<P CLASS=para>
<A NAME="CH20.JAVA.AWT.EVE1"></A>This package defines classes and interfaces used for event
handling in the AWT.  This package, and all of its classes
and interfaces, are new in Java 1.1.

<P CLASS=para>
The members of this package fall into three categories:

<P>
<UL CLASS=itemizedlist>
<li CLASS=listitem>Events. The classes with names ending in "Event" represent
specific types of events, generated by the AWT or by one of
the AWT components.

<P>
<li CLASS=listitem>Listeners. The interfaces in this package are all "event
listeners"; their names end with "Listener."  These interfaces
define the methods that must be implemented by any object that wants to
be notified when a particular event occurs.  Note that there
is a <tt CLASS=literal>Listener</tt> interface for each <tt CLASS=literal>Event</tt>
class.

<P>
<li CLASS=listitem>Adapters. Each of the classes with a name ending in "Adapter"
provides a no-op implementation for an event listener
interface that defines more than one method.  When you are
only interested in a single method of an event listener
interface, it is easier to subclass an <tt CLASS=literal>Adapter</tt> class
than to implement all of the methods of the corresponding
<tt CLASS=literal>Listener</tt> interface.

<P>
</UL>
<P CLASS=para>
<A HREF="ch20_01.htm#JNUT2-CH-20-FIG-1">Figure 20.1</A> 
shows the class hierarchy for this package.  See <A HREF="ch07_01.htm">Chapter 7, <i>Events</i></A>,
for more information on events and event handling.

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JNUT2-CH-20-FIG-1">Figure 20.1: The java.awt.event package</A></h4>


<p>
<img align=middle src="./figs/jn2_2001.gif" alt="[Graphic: Figure 20-1]" width=464 height=503 border=0>

</DIV>

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-20-SECT-1">20.1 java.awt.event.ActionEvent (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-20-SECT-1.1"></A></h3>
</DIV>

<P CLASS=para>
An object of this class represents a high-level "action"
event generated by an AWT component.  Instead of
representing a direct user event, such as a mouse or
keyboard event, <tt CLASS=literal>ActionEvent</tt> represents some sort of
action performed by the user on an AWT component.

<P CLASS=para>
The <tt CLASS=literal>getID()</tt> method returns the type of action that
has occurred.  For AWT-generated action events, this type is
always <tt CLASS=literal>ActionEvent.ACTION_PERFORMED</tt>; custom
components can generate action events of other types.

<P CLASS=para>
The <tt CLASS=literal>getActionCommand()</tt> method returns a
<tt CLASS=literal>String</tt> that serves as a kind of name for the action
that the event represents.  The <tt CLASS=literal>Button</tt> and
<tt CLASS=literal>MenuItem</tt> components have a
<tt CLASS=literal>setActionCommand()</tt> method that allows the programmer
to specify an "action command" string to be included with
any action events generated by those components.  It is this
value that is returned by the <tt CLASS=literal>getActionCommand()</tt>
method.  When more than one <tt CLASS=literal>Button</tt> or other
component notifies the same <tt CLASS=literal>ActionListener</tt>, you can
use <tt CLASS=literal>getActionCommand()</tt> to help determine the
appropriate response to the event.  This is generally a
better technique than using the source object returned by
<tt CLASS=literal>getSource()</tt>.  If no action command string is
explicitly set, <tt CLASS=literal>getActionCommand</tt> returns the label
of the <tt CLASS=literal>Button</tt> or <tt CLASS=literal>MenuItem</tt>.  Note, however,
that internationalized programs should not rely on these
labels to be constant.

<P CLASS=para>
Finally, <tt CLASS=literal>getModifiers()</tt> returns a value that
indicates what keyboard modifiers were in effect when the
action event was triggered.  Use the various <tt CLASS=literal>_MASK</tt>
constants, along with the <tt CLASS=literal>&amp;</tt> operator to decode this
value.

<DIV CLASS=screen>
<P>
<PRE>
public class <tt CLASS=literal>ActionEvent</tt> extends AWTEvent {
    // <tt CLASS=literal>Public Constructors</tt>
            public <tt CLASS=literal>ActionEvent</tt>(Object <tt CLASS=literal>source</tt>, int <tt CLASS=literal>id</tt>, String <tt CLASS=literal>command</tt>);
            public <tt CLASS=literal>ActionEvent</tt>(Object <tt CLASS=literal>source</tt>, int <tt CLASS=literal>id</tt>, String <tt CLASS=literal>command</tt>, int <tt CLASS=literal>modifiers</tt>);
    // <tt CLASS=literal>Constants</tt>
            public static final int <tt CLASS=literal>ACTION_FIRST</tt>;
            public static final int <tt CLASS=literal>ACTION_LAST</tt>;
            public static final int <tt CLASS=literal>ACTION_PERFORMED</tt>;
            public static final int <tt CLASS=literal>ALT_MASK</tt>;
            public static final int <tt CLASS=literal>CTRL_MASK</tt>;
            public static final int <tt CLASS=literal>META_MASK</tt>;
            public static final int <tt CLASS=literal>SHIFT_MASK</tt>;
    // <tt CLASS=literal>Public Instance Methods</tt>
            public String <tt CLASS=literal>getActionCommand</tt>();
            public int <tt CLASS=literal>getModifiers</tt>();
            public String <tt CLASS=literal>paramString</tt>();  //<tt CLASS=literal> Overrides AWTEvent</tt>
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-20-SECT-1.2">Hierarchy:</A></h3>

<P CLASS=para>
<tt CLASS=literal>Object->EventObject(Serializable)->AWTEvent->ActionEvent</tt>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-20-SECT-1.3">Passed To:</A></h3>

<P CLASS=para>
<tt CLASS=literal>ActionListener.actionPerformed(), 
AWTEventMulticaster.actionPerformed(), 
Button.processActionEvent(), 
List.processActionEvent(), 
MenuItem.processActionEvent(), 
TextField.processActionEvent()</tt>

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_06.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch20_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.awt.datatransfer.UnsupportedFlavorException (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.awt.event.ActionListener (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
